package cd.zhixuan.utils.recycler;

import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import cd.zhixuan.utils.R;


/**
 * Author:Hzc
 * Created on 2020/12/2
 */
public class SwiperMenuItem<DATA> {

    public enum Direction {
        LEFT, RIGHT
    }

    @NonNull
    public Direction direction = Direction.LEFT;
    @NonNull
    public String text;

    @DrawableRes
    public int bgDrawable;

    public SwiperMenuItem(@NonNull String text, @DrawableRes int drawable) {
        this.text = text;
        this.bgDrawable = drawable;
    }

    @Nullable
    public View onCreateView(@NonNull SwipeItemLayout layout, int menuItemIndex) {
        return null;
    }

    public void onViewCreated(@NonNull LinearLayout parent, @NonNull View view) {

    }

    public void onClicked(@NonNull RecyclerView.ViewHolder holder,
                          @NonNull SwiperMenuItem<DATA> menuItem,
                          @NonNull DATA data,
                          int position,
                          int swiperPos) {
        try {
            if (holder.itemView instanceof SwipeItemLayout) {
                ((SwipeItemLayout) holder.itemView).close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void onBindRecyclerItem(@NonNull SwipeItemLayout layout, RecyclerView.ViewHolder holder, View swiperView, int dataPos, int menuPos) {

    }


    public static int getTag(int position) {
        return R.id.tag_swipe_item + position;
    }

}
